{extends file="../acp.html"}

{block name="title"}{$head_title}{/block}
{block name="css"}
<link href="__PUBLIC__/Css/front/layer.css?version={$version}" type="text/css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="/Public/Css/acp/AcoContract/contract_list.css?version={$version}"/>
<style>
</style>
{/block}
{block name="content"}
<div class="tablesWrap">
    <div class="tables-searchbox">
        <form method="post">
            <span class="tbs-txt">企业名称：</span>
            <input type="text" name="company_name" value="{$company_name}">

             <span class="tbs-txt">退押金时间：</span>
             <input type="text" autocomplete="off" class="Wdate" name="start_date" value="{$start_date|date_format:'%Y-%m-%d %H:%M'}"  onclick="WdatePicker({ dateFmt:'yyyy-MM-dd HH:mm'})">
             <span class="tbs-txt">至</span>
             <input type="text" autocomplete="off" class="Wdate" name="end_date" value="{$end_date|date_format:'%Y-%m-%d %H:%M'}"  onclick="WdatePicker({ dateFmt:'yyyy-MM-dd HH:mm'})">


            <select name="is_out" class="small">
                <option value="-1" selected="">-押金是否已退-</option>
                <option value="0" {if $is_out == 0 } selected{/if}>否</option>
                <option value="1" {if $is_out == 1 } selected{/if}>是</option>
            </select>

            <select name="is_receipt" class="small">
                <option value="-1" selected="">-收据是否已开-</option>
                <option value="0" >否</option>
                <option value="1" >是</option>
            </select>


            <button type="submit" class="btn"><i class="gicon-search"></i>搜索</button>
        </form>
    </div>
<!-- end tables-searchbox -->  
<table class="wxtables">  
    <colgroup>  
    <!--<col width="6%">-->
    <col width="10%">
    <col width="6%">
    <col width="6%">
    <col width="8%">
    <col width="8%">
    <col width="10%">
    <col width="6%">
    <col width="10%">
    <col width="6%">
    <col width="6%">
    <col width="10%">
    </colgroup>
    <thead>
        <tr>
            <!--<td>选择</td>-->
            <td>企业名称</td>
            <td>面积</td>
            <td>工位</td>
            <td>应交押金</td>
            <td>已交押金</td>
            <td>到账时间</td>
            <td>押金是否已退</td>
            <td>退押金时间</td>
            <td>退租原因</td>
            <td>收据是否已开</td>
            <td>操作</td>
        </tr>  
    </thead>  
	{foreach from=$contract_list item=this}
    <tbody class="combo-tbody">  
        <tr>
            <!--<td><input type="checkbox" class="checkbox" value="{$item.item_id}" name="checkIds[]"></td>-->
			<td>{$this.company_name}</td>
			<td>{$this.total_area}</td>
			<td>{$this.total_station_num}</td>
			<td>{$this.deposit}</td>
			<td>{$this.pay_deposit}</td>
			<td>{$this.start_pay_time|date_format:"%Y-%m-%d %H:%M:%S"}</td>
            <td>{if $this.end_pay_time}是{else}否{/if}</td>
			<td>{if $this.end_pay_time}{$this.end_pay_time|date_format:"%Y-%m-%d %H:%M:%S"}{else}{/if}</td>
			<td>{$this.surrender_name}</td>
			<td>{if $this.is_receipt == 1}是{else}否{/if}</td>
            <td>
                {if !$this.pay_deposit}
				<a href="javascript:;" class="btn add_deposit" data-contract_id="{$this.contract_id}" title="押金登记">押金登记</a>
                {else}
                {if !$this.end_pay_time}
                <a href="javascript:;" class="btn end_deposit" data-deposit_id="{$this.deposit_id}" data-pay_deposit="{$this.pay_deposit}" title="退押金">退押金</a>
                {/if}
                {/if}
                <a href="javascript:;" class="btn look_housing" data-contract_id="{$this.contract_id}" title="查看房源信息">查看房源信息</a>
            </td>  
        </tr>
    </tbody>
	{foreachelse}   
    <tbody>    
		<tr>
			<td colspan="7">
				没有符合条件的记录
			</td>
		<tr>
    </tbody>  
	{/foreach}
</table>  
<!-- end wxtables -->  
<div class="tables-btmctrl clearfix">  
    <!--<div class="fl">  -->
        <!--<a href="javascript:;" class="btn btn-blue" onclick="Select()">全选</a>  -->
        <!--<a href="javascript:;" class="btn btn-blue" onclick="Cancel()">取消</a>  -->
        <!--<a href="javascript:;" onclick="batch_delete()" class="btn btn-blue">删除</a>-->
    <!--</div>  -->
    <div class="fr">  
        <div class="paginate">
			{$page_str} 
        </div>  
        <!-- end paginate -->  
    </div>  
</div>  
<!-- end tables-btmctrl -->  
</div>  
<!-- end tablesWrap -->   
{/block} 

{block name="js"}
<script src="/Public/Plugins/My97DatePicker/WdatePicker.js?version={$version}"></script>
<script src="__JS__/clipboard.min.js"></script>
<script src="__JS__/front/layer.m.js?version={$version}"></script>
{literal}
<script>
	//全选
	function Select(){
		var sel=document.getElementsByName("a[]");
		for(var i=0;i<sel.length;i++){
			sel[i].checked=true;
		}
	}
	//取消全选
	function Cancel(){
		var sel=document.getElementsByName("a[]");
		for(var i=0;i<sel.length;i++){
			sel[i].checked=false;
		}
	}

function delete_service_type(type_id)
{
	$.jPops.confirm(
	{  
		 title:"提示",  
		 content:"您确定要删除这条数据吗？",  
		 okBtnTxt:"确定",  
		 cancelBtnTxt:"取消",  
		 callback:function(r)
		 {  
			 if(r)
			 {
				 $.post('/AcpSiteType/delete_site_type', {"type_id":type_id}, function(data, textStatus)
				 {
					if (data == 'success')
					{
						alert('恭喜您，删除成功！');
						location.reload();
					}
					else
					{
						alert('对不起，场地类型下存在场地，删除失败！');
					}
				});
			 }  
			 return true;  
		 }
	 });  	
}

function batch_delete()
{
	$.jPops.confirm(
	{  
		 title:"提示",  
		 content:"您确定要删除这些数据吗？",  
		 okBtnTxt:"确定",  
		 cancelBtnTxt:"取消",  
		 callback:function(r)
		 {  
			 if(r)
			 {
				 var type_ids = '';
				 var count = 0;
				 $('input[name="a[]"]:checked').each(function(){
					 count ++;
                     type_ids += $(this).val() + ',';
				 });

				 if (!count)
				 {
					 alert('对不起，请选择至少一项进行删除！');
					 return;
				 }

                 type_ids = type_ids.substr(0, type_ids.length - 1);

				 $.post('/AcpSiteType/batch_delete_site_type', {"type_ids":type_ids}, function(data, textStatus)
				 {
					if (data == 'success')
					{
						alert('恭喜您，删除成功！');
						location.reload();
					}
					else
					{
						alert('对不起，场地类型下存在场地，删除失败！');
					}
				});
			 }  
			 return true;  
		 }
	 });
}
//复制商品链接
function class_link(class_id)
{
    var link = 'http://' + document.domain + '/FrontMall/item_list/class_id/' + class_id;
    $.jPops.custom({
        title:"请复制链接",  
        content:'<div>一级分类链接：' + link + '</div>',
        okBtnTxt:"复制",  
        cancelBtnTxt:"关闭",  
        callback:function(r)
        {
            if(r)
            {
                text = link;
                copy_text('jpops-btn-ok');
            }
            else
            {
                return true;  
            }
        }
    });
}
function copy_text(id)
    {
        var clipboard = new Clipboard('#' + id, {
            text: function() {
                return text;
            }
        });

        clipboard.on('success', function(e) {
            console.log(e);
            alert('复制成功');
        });

        clipboard.on('error', function(e) {
            console.log(e);
            alert('复制失败，请手动复制');
        });
    }

    //押金登记
    $("body").on("click",".data_th",function(){
        WdatePicker({ dateFmt:'yyyy-MM-dd HH:mm'});
    })
    $('.add_deposit').on("click",function(){
        var contract_id=$(this).attr('data-contract_id');

        var html='<form id="add_deposit_form">' +
                '<div class="formitems inline">'+
                '<label class="fi-name"><span class="colorRed">*</span>押金：</label>'+
                '<div class="form-controls">'+
                '<input name="pay_deposit" id="pay_deposit" ><span class="fi-help-text"></span>'+
                '</div>'+
                '</div>'+
                '<div class="formitems inline">'+
                '<label class="fi-name">到账日期：</label>'+
                '<div class="form-controls">'+
                '<input type="text" autocomplete="off" class="Wdate data_th"  name="start_time" id="start_time" value=""><span class="fi-help-text">不填则为当前日期 </span>'+
                '</div>' +
                '</div>'+
                '<div class="formitems inline">'+
                '<label class="fi-name"><span class="colorRed">*</span>是否开收据：</label>'+
                '<div class="form-controls">'+
                '<div class="radio-group">'+
                '<label><input type="radio" name="is_receipt" value="1" checked>是</label>'+
                '<label><input type="radio" name="is_receipt" value="0">否</label>'+
                '</div>'+
                '<span class="fi-help-text error"></span>'+
                '</div>'+
                '</div>'+
                '<input type="hidden" name="contract_id" value="'+contract_id+'" />'
                '</form>';

        $.jPops.custom({
            title:"押金登记",
            content:html,
            okBtnTxt:"确定",
            cancelBtnTxt:"取消",
            callback:function(r)
            {
                if(r){
                    $.validator.setDefaults(
                            {
                                //表单验证通过后的处理，异步提交表单
                                submitHandler: function()
                                {
                                    $.post('/AcpContract/add_deposit',$('form').serialize(),function(data)
                                    {
                                        console.log(data);
                                        if (data.code == 1 )
                                        {
                                            alert(data.msg);
                                            location.reload();
                                        }else{
                                            alert(data.msg);
                                        }
                                    })
                                    acp.batchDeliverFormStatus = true;
                                }
                            });

                    $("#add_deposit_form").validate(
                            {
                                rules:
                                {
                                    pay_deposit:
                                    {
                                        required: true,
                                        number:true
                                    },
                                },
                                messages:
                                {
                                    pay_deposit:
                                    {
                                        required: "对不起，请填写押金",
                                        number: "请填写数字!"
                                    },
                                },
                                errorPlacement: acp.form_ShowError,//显示出错信息(这段代码必须加)
                                success:acp.form_HideError//验证成功隐藏错误信息(这段代码必须加)
                            });

                    //模拟提交表单
                    $("#add_deposit_form").submit();
                    return acp.batchDeliverFormStatus;
                }else{
                    return true;
                }
            }

        });
    })

    //退押金
    $("body").on("click",".data_th",function(){
        WdatePicker({ dateFmt:'yyyy-MM-dd HH:mm'});
    })
    $('.end_deposit').on("click",function(){
        var deposit_id=$(this).attr('data-deposit_id');
        var pay_deposit=$(this).attr('data-pay_deposit');

        var html='<form id="end_deposit_form">' +
                '<div class="formitems inline">'+
                '<label class="fi-name"><span class="colorRed">*</span>押金：</label>'+
                '<div class="form-controls">'+
                '<input value="'+pay_deposit+'" disabled><span class="fi-help-text"></span>'+
                '</div>'+
                '</div>'+
                '<div class="formitems inline">'+
                '<label class="fi-name">退押金时间：</label>'+
                '<div class="form-controls">'+
                '<input type="text" autocomplete="off" class="Wdate data_th"  name="end_time" id="end_time" value=""><span class="fi-help-text">不填则为当前日期 </span>'+
                '</div>' +
                '</div>'+
                '<div class="formitems inline">'+
                '<label class="fi-name"><span class="colorRed">*</span>退租原因：</label>'+
                '<div class="form-controls">'+
                '<select class="" name="surrender_id" id="surrender_id">'+
                {/literal}
                '<option value="">--请选择退租原因--</option>'+
                {foreach from=$surrender_list item=item}
                '<option value="{$item.type_id}">{$item.type_name}</option>'+
                {/foreach}
                {literal}
                '</select><span class="fi-help-text"> </span>'+
                '</div>' +
                '</div>'+
                '<input type="hidden" name="deposit_id" value="'+deposit_id+'" />'
        '</form>';

        $.jPops.custom({
            title:"退押金",
            content:html,
            okBtnTxt:"确定",
            cancelBtnTxt:"取消",
            callback:function(r)
            {
                if(r){
                    $.validator.setDefaults(
                            {
                                //表单验证通过后的处理，异步提交表单
                                submitHandler: function()
                                {
                                    $.post('/AcpContract/end_deposit',$('form').serialize(),function(data)
                                    {
                                        console.log(data);
                                        if (data.code == 1 )
                                        {
                                            alert(data.msg);
                                            location.reload();
                                        }else{
                                            alert(data.msg);
                                        }
                                    })
                                    acp.batchDeliverFormStatus = true;
                                }
                            });

                    $("#end_deposit_form").validate(
                            {
                                rules:
                                {
                                    surrender_id:
                                    {
                                        required: true,
                                    },
                                },
                                messages:
                                {
                                    surrender_id:
                                    {
                                        required: "对不起，请选择退租原因",
                                    },
                                },
                                errorPlacement: acp.form_ShowError,//显示出错信息(这段代码必须加)
                                success:acp.form_HideError//验证成功隐藏错误信息(这段代码必须加)
                            });

                    //模拟提交表单
                    $("#end_deposit_form").submit();
                    return acp.batchDeliverFormStatus;
                }else{
                    return true;
                }
            }

        });
    })

    var html = '';
    //查看房源信息
    $('.look_housing').on("click",function(){
        var contract_id=$(this).attr('data-contract_id');
        $.ajax({
            type:'post',
            async:false,
            url:'/AcpContract/get_look_housing_info',
            data:{contract_id:contract_id},
            success:function (d) {
                var r = d.house_info;
                // console.log(r)
                var len = Object.keys(r).length;
                html='';
                if(d.type == 1){
                    for(var i=0 ; i < len ; i++){
                        html+= '<div class="house-info park-house-info">\
                                <h6 class="house-title">房源'+(i+1)+'</h6>\
                                <ul class="park-mid clearfix">\
                                <li class="mid-list fl">\
                                <label class="list-label fl park-name-label">\
                                <span class="colorRed fl">*</span>\
                                <span class="fl">园区名</span>\
                                </label>\
                                <input type="text" class="house-area fl" value="'+r[i].incubator_name+'" disabled />\
                                </li>\
                                <li class="mid-list fl mg-list">\
                                <label class="list-label fl">\
                                <span class="colorRed fl">*</span>\
                                <span class="fl">楼层</span>\
                                </label>\
                                <input type="text" class="house-area fl" value="'+r[i].storey_name+'" disabled />\
                                </li>\
                                <li class="mid-list fl">\
                                <label class="list-label fl">\
                                <span class="colorRed fl">*</span>\
                                <span class="fl">房间</span>\
                                </label>\
                                <input type="text" class="house-area fl" value="'+r[i].station_type_name+'" disabled />\
                                </li>\
                                </ul>\
                                <ul class="park-bot clearfix">\
                                <li class="mid-list fl mg-right">\
                                <label class="list-label fl">\
                                <span class="colorRed fl">*</span>\
                                <span class="fl">租赁面积</span>\
                                </label>\
                                <input type="text" class="house-area fl" value="'+r[i].area+'" disabled/>\
                                </li>\
                                <li class="mid-list fl">\
                                <label class="list-label fl">\
                                <span class="colorRed fl">*</span>\
                                <span class="fl">租赁单价</span>\
                                </label>\
                                <input type="text" class="house-price fl" value="'+r[i].unit_price+'" disabled/>\
                                </li>\
                                </ul>\
                                </div>';
                    }
                }else{
                    for(var i=0 ; i < len ; i++){
                        html += '<div class="house-info zhongc-house-info">\
                            <h6 class="house-title">房源'+(i+1)+'</h6>\
                            <ul class="zhongc-mid clearfix">\
                                <li class="mid-list fl">\
                                    <label class="list-label fl zhongc-name-label">\
                                        <span class="colorRed fl">*</span>\
                                        <span class="fl">众创空间名</span>\
                                    </label>\
                                    <input type="text" class="house-area fl" value="'+r[i].incubator_name+'" disabled />\
                                </li>\
                                <li class="mid-list fl" >\
                                    <label class="list-label fl">\
                                        <span class="colorRed fl">*</span>\
                                        <span class="fl">楼层</span>\
                                    </label>\
                                    <input type="text" class="house-area fl" value="'+r[i].storey_name+'" disabled />\
                                </li>\
                                <li class="mid-list fl">\
                                    <label class="list-label fl">\
                                        <span class="colorRed fl">*</span>\
                                        <span class="fl">工位类型</span>\
                                    </label>\
                                    <input type="text" class="house-area fl" value="'+r[i].class_name+'" disabled />\
                                </li>\
                            </ul>\
                            <ul class="show-station clearfix">';
                            for (var j = 0; j < r[i].station_list.length; j++) {
                                html += '<li class="fl" >'+r[i].station_list[j].station_num+'</li>'
                            }
                            html += '</ul>\
                            </div>'
                    }
                }
                
            }
        })
    
        $.jPops.custom({
            title:"房源信息",
            content:html,
            okBtnTxt:"确定",
            cancelBtnTxt:"取消",
            callback:function(r)
            {
                    return true;
            }

        });
    })



</script>
{/literal}
{/block} 

{block name="css"}
<link type="text/css" rel="stylesheet" href="__ACPCSS__/tip.css" />
{literal}
<style>
.PageNext{page-break-after: always; height:1px;}
</style>
{/literal}
{/block} 
